import { getLogisticsTypeApi } from '../../api/order'

Component({
  options: {
    styleIsolation: 'shared'
  },
  /**
   * 组件的属性列表
   */
  properties: {
    type: {
      type: String,
      value: ''
    },
    orderId: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    list: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async showPopup() {
      const [err, list] = await getLogisticsTypeApi({
        orderId: this.data.orderId,
        type: this.data.type
      })
      if (err) return

      this.setData({
        show: true,
        list
      })
    },

    closeHandle() {
      this.setData({
        show: false
      })
    },

    copyHandle(e) {
      wx.setClipboardData({
        data: e.currentTarget.dataset.value,
        success: (res) => {
          wx.showToast({
            title: '复制成功',
            icon: 'none'
          })
        },
        fail: (res) => {
          wx.showToast({
            title: '复制失败',
            icon: 'none'
          })
        }
      })
    }
  }
})
